package editor.manager;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JSplitPane;

import editor.Context;
import editor.Mode;

/**
 * Workspace Manager
 * 
 * @author Mark Dessain
 */
@SuppressWarnings("serial")
public class WorkSpaceManager extends JPanel implements Manager
{
	
	public final static TextAreaManager textAreaManager = new TextAreaManager();
	public final static TestingManager  testingManager = new TestingManager();
	public final static ConsoleManager  consoleManager = new ConsoleManager();
	
	private JSplitPane codingSplit;
	
	/**
	 * WorkSpace
	 */
	public WorkSpaceManager()
	{
		JSplitPane projectSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textAreaManager, consoleManager);
		projectSplit.setResizeWeight(1D);
		
		codingSplit = projectSplit;
		codingSplit.setDividerLocation(Context.getScreenDimensions().height - 300);
		
		setLayout(new BorderLayout());
		codingMode();
	}

	/* (non-Javadoc)
	 * @see editor.manager.Manager#switchMode(editor.Mode)
	 */
	@Override 
	public void switchMode(Mode mode)
	{
		if(mode == Mode.CODING)
		{
			codingMode();
		}
		else if(mode == Mode.QUESTION)
		{
			questionMode();	
		}
		else if(mode == Mode.TESTING)
		{
			testingMode();
		}
		
		textAreaManager.switchMode(mode);
		consoleManager.switchMode(mode);
	}
	
	/* (non-Javadoc)
	 * @see editor.manager.Manager#codingMode()
	 */
	@Override
	public void codingMode() 
	{	
		this.removeAll();
		this.add(codingSplit);
		this.revalidate();
		this.repaint();	
	}

	/* (non-Javadoc)
	 * @see editor.manager.Manager#questionMode()
	 */
	@Override
	public void questionMode() 
	{	
		this.removeAll();
		this.add(codingSplit);
		this.revalidate();
		this.repaint();	
	}

	/* (non-Javadoc)
	 * @see editor.manager.Manager#testingMode()
	 */
	@Override
	public void testingMode() 
	{
		this.removeAll();
		this.add(testingManager);
		this.revalidate();
		this.repaint();		
	}

}